package com.hzsoft.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.Tag;

/**
 * <p>
 * 类描述：elseif
 * </p>
 * <p>
 * 创建人：liuyidong <br>
 * 创建时间：2012-5-4 上午11:43:26
 * </p>
 * <p>
 * 修改人：无 <br>
 * 修改时间：无 <br>
 * 修改备注：无
 * </p>
 * @version 1.0
 */
public class ElseIfTag extends BodyTagSupport{ 
	private static final long serialVersionUID = 726923844625494193L;

	public ElseIfTag() { 
        super(); 
        init(); 
    } 
  
    @Override
    public int doStartTag() throws JspException { 
        Tag parent = getParent(); 
  
        if(parent==null || !(parent instanceof IfTag)){ 
            throw new JspTagException("else tag must inside if tag"); 
        } 
          
        IfTag ifTag = (IfTag)parent; 
        if(ifTag.isSucceeded()){ 
            // 已经有执行成功的条件，保存之前的html 
            ifTag.setBody(); 
        }else if(test){     // 当前条件为true,之前无条件为true 
            ifTag.succeeded(); 
            // 则清除之前的输出 
            ifTag.getBodyContent().clearBody(); 
        } 
              
        return EVAL_BODY_BUFFERED; 
    } 
       
    @Override
    public void release() { 
        super.release(); 
        init(); 
    } 
      
    private void init() { 
        test = false; 
    } 
      
    private boolean test;   
      
    public void setTest(boolean test) { 
        this.test = test; 
    } 
}